﻿using System;
using System.Dynamic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ReflexTérkép.Tests.dto;

namespace ReflexTérkép.Tests
{
    [TestClass]
    public class MappingToGuidTests : TestBase
    {
        [TestMethod]
        public void Can_Map_Guid_Values_To_Guid_Properties()
        {
            // Arrange
            const int id = 1;
            const string firstName = "Bob";
            const string lastName = "Smith";
            Guid uniqueId = Guid.NewGuid();

            dynamic dynamicPerson = new ExpandoObject();
            dynamicPerson.Id = id;
            dynamicPerson.FirstName = firstName;
            dynamicPerson.LastName = lastName;
            dynamicPerson.UniqueId = uniqueId;

            // Act
            PersonWithGuidProperties customer = ReflexMapper.MapDynamic<PersonWithGuidProperties>(dynamicPerson);

            // Assert
            Assert.IsNotNull(customer);
            Assert.IsTrue(customer.Id == id);
            Assert.IsTrue(customer.FirstName == firstName);
            Assert.IsTrue(customer.LastName == lastName);
            Assert.IsTrue(customer.UniqueId == uniqueId);
        }

        [TestMethod]
        public void Can_Map_Guid_String_Values_To_Guid_Properties()
        {
            // Arrange
            const int id = 1;
            const string firstName = "Bob";
            const string lastName = "Smith";
            Guid uniqueId = Guid.NewGuid();

            dynamic dynamicPerson = new ExpandoObject();
            dynamicPerson.Id = id;
            dynamicPerson.FirstName = firstName;
            dynamicPerson.LastName = lastName;
            dynamicPerson.UniqueId = uniqueId.ToString(); // This is what we are testing

            // Act
            PersonWithGuidProperties customer = ReflexMapper.MapDynamic<PersonWithGuidProperties>(dynamicPerson);

            // Assert
            Assert.IsNotNull(customer);
            Assert.IsTrue(customer.Id == id);
            Assert.IsTrue(customer.FirstName == firstName);
            Assert.IsTrue(customer.LastName == lastName);
            Assert.IsTrue(customer.UniqueId == uniqueId); // This is what we are testing

        }
        [TestMethod]
        public void Can_Map_Null_Values_To_Guid_Properties()
        {
            // Arrange
            const int id = 1;
            const string firstName = "Bob";
            const string lastName = "Smith";
            Guid uniqueId = Guid.NewGuid();
            Guid? aNullableUniqueId = null;

            dynamic dynamicPerson = new ExpandoObject();
            dynamicPerson.Id = id;
            dynamicPerson.FirstName = firstName;
            dynamicPerson.LastName = lastName;
            dynamicPerson.UniqueId = uniqueId.ToString();
            dynamicPerson.ANullableUniqueId = aNullableUniqueId; // This is what we are testing

            // Act
            PersonWithGuidProperties customer = ReflexMapper.MapDynamic<PersonWithGuidProperties>(dynamicPerson);

            // Assert
            Assert.IsNotNull(customer);
            Assert.IsTrue(customer.Id == id);
            Assert.IsTrue(customer.FirstName == firstName);
            Assert.IsTrue(customer.LastName == lastName);
            Assert.IsTrue(Equals(customer.UniqueId, uniqueId));
            Assert.IsTrue(customer.ANullableUniqueId == aNullableUniqueId); // This is what we are testing

        }
    }
}
